package com.csmk.springboot_simple.util;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;

public class Null {

    public static boolean hasEmpty(Object ... objs){
        for (Object obj : objs) {
            if (!isEmpty(obj)){
                return false;
            }
        }
        return true;
    }

    public static boolean hadBlank(CharSequence ... css){
        for (CharSequence cs : css) {
            if (isBlank(cs)){
                return true;
            }
        }
        return false;
    }

    public static boolean isEmpty(Object obj){
        if (obj == null) {
            return true;
        } else if (obj instanceof CharSequence) {
            return ((CharSequence)obj).length() == 0;
        } else if (obj.getClass().isArray()) {
            return Array.getLength(obj) == 0;
        } else if (obj instanceof Collection) {
            return ((Collection)obj).isEmpty();
        } else {
            return obj instanceof Map ? ((Map)obj).isEmpty() : false;
        }
    }

    public static boolean isNotEmpty(Object obj){
        return !isEmpty(obj);
    }
    public static boolean isBlank(CharSequence cs){
        int strLen = cs == null ? 0 : cs.length();
        if (strLen == 0) {
            return true;
        } else {
            for(int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(cs.charAt(i))) {
                    return false;
                }
            }

            return true;
        }
    }
}
